package Hxw3DEngine.core.component {

	import flash.display3D.Context3D;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.geom.Matrix3D;
	import Hxw3DEngine.core.component.IComponent;
	import Hxw3DEngine.core.controller.Camera3D;
	import Hxw3DEngine.core.display.GameObject;
	import Hxw3DEngine.core.controller.Scene3D;
	
	/**
	 * 组件基类，实现了组件的接口 再往下扩展
	 */	
	public class Component3D extends EventDispatcher implements IComponent {
		
		/** 启用组件 */
		public static const ENABLE_EVENT 	: String = "Component3D:ENABLE";
		/** disable */
		public static const DISABLE_EVENT   : String = "Component3D:DISABLE";
		// 事件
		private static const enableEvent    : Event = new Event(ENABLE_EVENT);
		private static const disableEvent   : Event = new Event(DISABLE_EVENT);
		
		protected var _object3d : GameObject;	// 宿主
		protected var _enable   : Boolean;	// 是否启用
		protected var _disposed : Boolean;	// 是否被摧毁
		protected var _type		:String ;	//当前组件类型 ComponentType枚举
		
		public function Component3D() {
			super();
			this._enable = true;
			this._type = ComponentType.dynamicComponent;//默认全是动态组件
		}
		
		/**
		 * master 
		 * @return 
		 * 
		 */		
		public function get object3D():GameObject {
			return _object3d;
		}
		
		/**
		 * 被添加到DisplayObject3D 
		 * @param master
		 * 
		 */		
		public function onAdd(master : GameObject) : void {
			this._object3d = master;
		}
		
		/**
		 * DisplayObject3D添加了其它组件 
		 * @param component
		 * 
		 */		
		public function onOtherComponentAdd(component : IComponent) : void {

		}
		
		/**
		 * DisplayObject3D移除了其它组件 
		 * @param component
		 * 
		 */		
 		public function onOtherComponentRemove(component : IComponent) : void {

		}

		/**
		 * 组件被移除 
		 * @param master
		 * 
		 */		
		public function onRemove(master : GameObject) : void {
			this._object3d = null;
		}
		
		/**
		 * 进入帧循环 
		 * 
		 */		
		public function onUpdate() : void {
			
		}
		
		/**
		 * 开始绘制 
		 * @param scene
		 * 
		 */		
		public function onDraw() : void {
			
		}
		
		/**
		 * 开/关组件 
		 * @param value
		 * 
		 */		
		public function set enable(value : Boolean) : void {
			if (enable == value) {
				return;
			}
			this._enable = value;
			if (value && hasEventListener(ENABLE_EVENT)) {
				this.dispatchEvent(enableEvent);
			} else if (hasEventListener(DISABLE_EVENT)) {
				this.dispatchEvent(disableEvent);
			}
		}
		
		/**
		 * 是否启用 
		 * @return 
		 */		
		public function get enable() : Boolean {
			return _enable;
		}
		
		/**
		 * 克隆 
		 * @return 
		 * 
		 */		
		public function clone() : IComponent {
			var c : Component3D = new Component3D();
			return c;
		}
		
		/**
		 * 销毁 
		 * 
		 */		
		public function dispose(force : Boolean = false) : void {
			this._disposed = true;
		}
		
		/**
		 * 是否被摧毁 
		 * @return 
		 * 
		 */		
		public function get disposed() : Boolean {
			return _disposed ;
		}
		
		/**
		 * 类型
		 */	
		public function get type():String {
			return _type;	
		}
		

	}
}
